package org.lex.ftplist.ui.common;

import java.util.Date;

import org.apache.commons.net.ftp.FTPFile;
import org.lex.collection.tree.TreeNode;
import org.netbeans.swing.outline.RowModel;

public class FtpFileRowModel implements RowModel {

    private static final String[] COLUMN_NAMES = {"Size", "Date"};
    private static final Class<?>[] COLUMN_CLASSES = {Long.class, Date.class};
    private static final int COLUMN_COUNT = COLUMN_NAMES.length;

    @Override
    public Class<?> getColumnClass(int column) {
        return COLUMN_CLASSES[column];
    }

    @Override
    public int getColumnCount() {
        return COLUMN_COUNT;
    }

    @Override
    public String getColumnName(int column) {
        return COLUMN_NAMES[column];
    }

    @Override
    public Object getValueFor(Object value, int column) {
        FTPFile file = (FTPFile) ((TreeNode) value).getData();
        if (null == file) {
            return null;
        }
        if (0 == column) {
            return file.getSize();
        } else {
            long time = 0L;
            if (null != file.getTimestamp()) {
                time = file.getTimestamp().getTimeInMillis();
            } else {
                time = System.currentTimeMillis();
            }
            return new Date(time);
        }
    }

    @Override
    public boolean isCellEditable(Object val, int column) {
        return false;
    }

    @Override
    public void setValueFor(Object object, int column, Object newValue) {
    }
}